<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>供应商列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '新增',
            iconCls: 'icon-edit',
            handler: function () {
                $('#dd-add').dialog('open');
            }
        }, {
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                $('#dd').dialog('open');
                let row = $("#booklist").datagrid("getSelected");
                $("#update-supplier-id").val(row.id);

                $("#supplier-name-id").textbox("setValue", row.name);
                $("#supplier-linkman-id").textbox("setValue", row.linkman);
                $("#supplier-phone-id").textbox("setValue", row.phone);
                $("#supplier-info-id").text(row.info);

            }
        }, '-', {
            text: '启用',
            iconCls: 'icon-ok',
            handler: function () {
                let row = $("#booklist").datagrid("getSelected");
                $.post("/manager/supplier/update", {id: row.id, flag: 1}, rs => {
                    if (rs.status == 200) {
                        $('#booklist').datagrid("reload");
                    } else {
                        alert(rs.msg);
                    }
                });
            }
        }, '-', {
            text: '禁用',
            iconCls: 'icon-cancel',
            handler: function () {
                let row = $("#booklist").datagrid("getSelected");
                $.post("/manager/supplier/update", {id: row.id, flag: 0}, rs => {
                    if (rs.status == 200) {
                        $('#booklist').datagrid("reload");
                    } else {
                        alert(rs.msg);
                    }
                });
            }
        }];
        $(function () {
            $('#booklist').datagrid({
                title: '供应商列表',
                iconCls: 'icon-save',
                url: '/manager/supplier/platformFindAll',
                columns: [
                    [
                        {field: 'name', title: '供应商名称', width: 100, align: 'center'},
                        {field: 'linkman', title: '联系人', width: 200, align: 'center'},
                        {field: 'phone', title: '联系电话', width: 80, align: 'center'},
                        {
                            field: 'flag', title: '是否启用', width: 200, align: 'center',
                            formatter: function (value, row, index) {
                                return value == "1" ? "启用" : "禁用";
                            }
                        },
                        {field: 'createtime', title: '入驻日期', width: 200, align: 'center'},
                        {field: 'totalnumber', title: '累计进货数', width: 200, align: 'center'},
                        {field: 'totalselnum', title: '累计销售数', width: 200, align: 'center'},
                        {field: 'degree', title: '等级', width: 200, align: 'center'},
                    ]],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            });

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    let data = {};
                    let name = $("#search-supplier-name").val();
                    if (name != "") {
                        data.name = name;
                    }
                    $('#booklist').datagrid("reload", data);
                });

            //初始化新增窗口
            $('#dd-add').dialog({
                title: '新增供应商',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $.post("/manager/supplier/add", $("#ff-add").serialize(), rs => {
                            if (rs.status == 200) {
                                $('#booklist').datagrid("reload");
                            } else {
                                alert(rs.msg);
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd-add').dialog("close");
                    }
                }]
            });
            //初始化修改窗口
            $('#dd').dialog({
                title: '修改供应商',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $.post("/manager/supplier/update", $("#ff").serialize(), rs => {
                            if (rs.status == 200) {
                                $('#booklist').datagrid("reload");
                            } else {
                                alert(rs.msg);
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog("close");
                    }
                }]
            });

        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>供应商查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" id="search-supplier-name" size=20 placeholder="供应商名称"/>
    </td>
    <td>
        <a id="submit_search">搜索</a>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff" method="post">
            <input id="update-supplier-id" name="id" type="hidden">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"
                       id="supplier-name-id"
                       name="name" style="width:50%" data-options="label:'供应商名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="linkman"
                       id="supplier-linkman-id"
                       style="width:50%" data-options="label:'联系人:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="phone"
                       id="supplier-phone-id"
                       style="width:50%" data-options="label:'联系电话:',required:true">
            </div>
            <table>
                <tr style="vertical-align:top">
                    <td>
                        公司简介:
                    </td>
                    <td>
                        <textarea rows="10" cols="30" id="supplier-info-id" name="info"></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>


<div id="dd-add">
    <div align="center" style="margin-top: 30px">
        <form id="ff-add" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="name" style="width:50%" data-options="label:'供应商名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="linkman" style="width:50%"
                       data-options="label:'联系人:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="phone" style="width:50%" data-options="label:'联系电话:',required:true">
            </div>
            <table>
                <tr style="vertical-align:top">
                    <td>
                        公司简介:
                    </td>
                    <td>
                        <textarea rows="10" cols="30" name="info"></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>